<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>编辑社群</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <style>
        .childrenBody{
            padding: 30px;
        }
    </style>
</head>
<body class="childrenBody">
<form class="layui-form html_save" lay-filter="form">
    <input class="layui-input" name="id" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">社群ID(明文)</label>
        <div class="layui-input-block">
            <input class="layui-input" name="groupId" lay-verify="required" placeholder="请输入社群ID(明文)" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">社群名称</label>
        <div class="layui-input-block">
            <input class="layui-input" name="groupName" placeholder="请输入社群名称" type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">社群介绍</label>
        <div class="layui-input-block">
            <input class="layui-input" name="groupIntroduce" placeholder="请输入社群介绍" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">社群图片</label>
        <div class="layui-input-block">
            <input class="layui-input" name="groupUrl" placeholder="社群图片" type="text">
        </div>

        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">上传</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览图：
                <div class="layui-upload-list" id="demo1"></div>
            </blockquote>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveContainer">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/cba/login-timeout.js}"></script>
<!--<script type="text/javascript" src="js/newsadd.js"></script>-->

<script type="text/javascript" th:inline="javascript">
    layui.use(['table', 'form', "layer",'upload'], function () {

        // 操作对象
        var form = layui.form
            , upload = layui.upload
            , layer = layui.layer
            , $ = layui.jquery;

        //执行上传
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            , url: [[${basePath}]] + '/upload/oss'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').html('<img style="width: 50px;height: 50px;" src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
                });
            }
            , done: function (res) {
                $("input[name='groupUrl']").val('' + res.data);
            }
            , error: function () {
                //请求异常回调
            }
        });

        var manage = [[${manage}]];
        if (manage != null) {
            form.val("form", {
                "id": manage.id,
                "groupId": manage.groupId
                ,"groupName": manage.groupName
                ,"groupIntroduce": manage.groupIntroduce
            });
            $('#demo1').html('<img style="width: 50px;height: 50px;" src="'+ manage.groupUrl +'" alt="xxx.jpg" class="layui-upload-img">')
        }


        //监听提交
        form.on('submit(saveContainer)', function (data) {
            $.ajax({
                url: [[${basePath}]] + "/group/groupManageEdit",
                data: data.field,
                type: "post",
                success: function (data) {
                    console.log(data);
                    if (data.success) {
                        layer.msg(data.msg, {icon: 1});
                        setTimeout(function () {
                            parent.layui.table.reload("dataCheck");
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                        }, 1500);
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                }
            });

            return false;
        });

    });

    function queryImgs(goodsId) {
        debugger

    }
</script>
</body>
</html>